#ifndef _GLWIDGET_H_
#define _GLWIDGET_H_

#include <QtOpenGL/qgl.h>
#include <QKeyEvent>
#include <iostream>
#include <QString>
#include <QFileDialog>
#include <QTimer>
#include <QElapsedTimer>

#include "Point.h"
#include "Scene.h"

typedef enum { NONE, ROTATE, ZOOM, PAN } InteractiveAction;

class  GLWidget : public QGLWidget  // CAG
{
    Q_OBJECT

public:
    //__declspec(dllexport) GLWidget(QWidget * parent);
    GLWidget(QWidget * parent);


    void wheelEvent(QWheelEvent *e);
public slots:
    void help(void);
    void toggleAcceleration(bool);
    void LoadModel();
    void info(void);
    void setFacesPerNode(int);

signals:
    void UpdatedVertexs(int);
    void ObscurancesCalculated(double);
    void ObscurancesWithAccelerationCalculated(double);
    void AmbientOclusionCalculated(double);
    void AmbienOclusionWithAccelerationCalculated(double);

protected:
    virtual void initializeGL();
    virtual void paintGL( void );
    virtual void resizeGL (int width, int height);

    virtual void keyPressEvent(QKeyEvent *e);
    virtual void mousePressEvent( QMouseEvent *e);
    virtual void mouseReleaseEvent( QMouseEvent *);
    virtual void mouseMoveEvent(QMouseEvent *e);

    void computeCameraInicial();
    void setModelview();
    void setProjection();


    Point getObs();

private:
    float anglecam;
    float ra;
    double anterior, posterior;
    Point VRP;
    float dist;
    float angleX, angleY, angleZ;

    Scene escena;  // Escena a representar en el widget

    // interaccio
    InteractiveAction DoingInteractive;

    int   xClick, yClick;

    bool lighting;

    QTimer timerRender;
    QElapsedTimer timerCalc;


    bool renderFilled;
    bool renderBVH;

    bool acceleration;
    RenderMode renderMode;
    bool detectCorners;
    bool debug;

    int renderLevelBVH;

    Ray ray;
};

#endif
